package com.bhprod.comatule.slideshow;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.bhprod.comatule.R;
import com.bhprod.comatule.db.DBDataSource;
import com.bhprod.comatule.detail.SpeciesDetailActivity;
import com.bhprod.comatule.model.Species;

public class SlideshowActivity extends FragmentActivity {

	private ViewPager pager;
	private SlideshowAdapter pagerAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.slideshow);
		
		Bundle b = getIntent().getExtras();
		ArrayList<Integer> speciesIds = b.getIntegerArrayList("speciesIds");
		
		pager = (ViewPager) findViewById(R.id.pagerSlideshow);
		pagerAdapter = new SlideshowAdapter(getSupportFragmentManager(), this);
		pagerAdapter.setSpecies(DBDataSource.getInstance().getSpeciesByIds(speciesIds));
		pager.setAdapter(pagerAdapter);
	}

//	@Override
//	public void onBackPressed() {
//		if (pager.getCurrentItem() == 0) {
//			// If the user is currently looking at the first step, allow the
//			// system to handle the
//			// Back button. This calls finish() on this activity and pops the
//			// back stack.
//			super.onBackPressed();
//		} else {
//			// Otherwise, select the previous step.
//			pager.setCurrentItem(pager.getCurrentItem() - 1);
//		}
//	}
	
	public void displayDetail(View view) {
		Species currentSpecies = pagerAdapter.getSpecies().get(pager.getCurrentItem());
		Intent intent = new Intent(this, SpeciesDetailActivity.class);
		Bundle b = new Bundle();
		b.putInt("speciesId", currentSpecies.getId());
		intent.putExtras(b);
		startActivity(intent);
	}

}
